from socket import *
from multiprocessing import Process


HOST = "0.0.0.0"
PORT = 8888
ADDR = (HOST, PORT)


def handle(conn, addr):
    while True:
        data = conn.recv(1024)
        if not data:
            break
        print(addr, "-----", data.decode())
        conn.send(b"OK")
    conn.close()


def main():
    sock = socket()
    sock.bind(ADDR)
    sock.listen()

    print("listen ... ...")

    while True:
        conn, addr = sock.accept()
        print("Connect from", addr)
        p = Process(target=handle, args=(conn, addr))
        p.start()


if __name__ == '__main__':
    main()
